package ch.unisi.inf.projects.java.uom.gui.commands;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;

import javax.swing.KeyStroke;

import ch.unisi.inf.projects.java.uom.Parser;
import ch.unisi.inf.projects.java.uom.exceptions.UOMException;
import ch.unisi.inf.projects.java.uom.elements.Item;
import ch.unisi.inf.projects.java.uom.gui.itemeditor.fieldselector.ListEntryGUIDialog;

public class OpenListCommand extends Command {
	/** We are not going to serialize this class atm */
	private static final long serialVersionUID = -1L;
	
	final Item item;
	
	final String key;
	
	final String value;
		
    public OpenListCommand (final Item item, final String key, final String value)
    {
    	this.item = item;
    	this.key = key;
    	this.value = value;
    	String label;
    	try {
    		label = Parser.instance().dbGetListTypeVar(key);
    	}
    	catch (final UOMException uome) {
    		label = "";
    	}
        putValue(NAME,"Open list of " + label);
        putValue(SHORT_DESCRIPTION,"Opens the list of elements");
        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    }
    
    public void actionPerformed(final ActionEvent ev)
    {
    	new ListEntryGUIDialog(item, key, value);
    }
}